package com.yenlien.traceyun.business.controller;


import com.yenlien.traceyun.business.entity.Client;
import com.yenlien.traceyun.business.interceptor.UserAuthUtil;
import com.yenlien.traceyun.business.service.ClientService;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by LiuSha on 2020/6/8.
 */
@RestController
@RequestMapping(value = "/client")
public class ClientController extends BaseController {
    @Autowired
    private ClientService clientService;

    @RequestMapping(value = "/findByList", method = RequestMethod.POST)
    public Object findByList(@RequestBody Client client) {
        client.setCompanyId(UserAuthUtil.getLoginUser().getCompanyId());
        return buildPage(clientService.findByList(client));
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody Client client) {
        client.setCompanyId(UserAuthUtil.getLoginUser().getCompanyId());
        clientService.save(client);
        return success("success");
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Object update(@RequestBody Client client) {
        clientService.update(client);
        return success("success");
    }

    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
    public Object findById(@PathVariable String id) {
        return success(clientService.findById(id));
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public Object delete(@PathVariable String id) {
        clientService.delete(id);
        return success("success");
    }

    @RequestMapping(value = "/findByAll", method = RequestMethod.GET)
    public Object findByAll() {
        return success(clientService.findAll(UserAuthUtil.getLoginUser().getCompanyId()));
    }


}
